home *** CD-ROM | disk | FTP | other *** search
- program TestAAHpDist;
-
- {$APPTYPE CONSOLE}
-
- uses
- AAHpDist in 'AAHpDist.pas',
- SysUtils;
-
- var
- PtrArray : array [0..127] of pointer;
- i : integer;
- TotalGets: integer;
-
- begin
- writeln('Testing AAHpDist...');
- try
-
-
- {at this point the replacement heap manager should be installed}
- Assert(IsMemoryManagerSet, 'Heap manager has not been replaced');
-
- {clear the bins--gets rid of the allocations SysUtils makes}
- FillChar(aaHeapBins, sizeof(aaHeapBins), 0);
-
- writeln('allocate 128 pointers');
- for i := 0 to 127 do
- GetMem(PtrArray[i], Random(512) + 1);
-
- writeln('free every even element');
- for i := 0 to 127 do
- if not Odd(i) then begin
- FreeMem(PtrArray[i]);
- PtrArray[i] := nil;
- end;
-
- writeln('reallocate every odd element');
- for i := 0 to 127 do
- if Odd(i) then
- ReallocMem(PtrArray[i], Random(512) + 1);
-
- writeln('free every odd element');
- for i := 0 to 127 do
- if Odd(i) then begin
- FreeMem(PtrArray[i]);
- PtrArray[i] := nil;
- end;
-
- writeln('making sure there are 192 allocations');
- TotalGets := 0;
- for i := low(aaHeapBins) to high(aaHeapBins) do
- inc(TotalGets, aaHeapBins[i]);
- Assert(TotalGets=192, 'The Total allocations is wrong');
-
- writeln('done');
- except
- on E : Exception do
- writeln(E.Message);
- end;
- write('Press Enter to close...');
- readln;
- end.
-